Get rid of xenbus_uuid_to_domid - get the frontend id from the node.
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Thu, 18 Aug 2005 19:21:09 +0000 (19:21 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Thu, 18 Aug 2005 19:21:09 +0000 (19:21 +0000)
We don't want to parse paths we read out of the store to _construct_
other paths and tie down the store layout for no good reason.
Also require the frontend path to exist and be valid before creating
the device.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
linux-2.6-xen-sparse/include/asm-xen/xenbus.h

index 06b33fd6459cb7982239946549bd1dc4a689afdb..cfdd92fcdddedd7e9cfa2af1577e4ee4a35bf879 100644 (file)
@@ -109,47 +109,41 @@ static struct xen_bus_type xenbus_frontend = {
        },
 };
 
-/* For backends, does lookup on uuid (up to /).  Returns domid, or -errno. */
-int xenbus_uuid_to_domid(const char *uuid)
-{
-       int err, domid, len;
-       char path[strlen("/domain/") + 50];
-
-       len = strcspn(uuid, "/");
-       if (snprintf(path, sizeof(path), "/domain/%.*s", len, uuid)
-           >= sizeof(path))
-               return -ENOSPC;
-       err = xenbus_scanf(path, "id", "%i", &domid);
-       if (err != 1)
-               return err;
-       return domid;
-}
-
 /* backend/<type>/<fe-uuid>/<id> => <type>-<fe-domid>-<id> */
 static int backend_bus_id(char bus_id[BUS_ID_SIZE], const char *nodename)
 {
-       unsigned int typelen, uuidlen;
-       int domid;
-       const char *p;
+       int domid, err;
+       const char *devid, *type, *frontend;
+       unsigned int typelen;
 
-       nodename = strchr(nodename, '/');
-       if (!nodename)
-               return -EINVAL;
-       nodename++;
-       typelen = strcspn(nodename, "/");
-       if (!typelen || nodename[typelen] != '/')
+       type = strchr(nodename, '/');
+       if (!type)
                return -EINVAL;
-       p = nodename + typelen + 1;
-       uuidlen = strcspn(p, "/");
-       if (!uuidlen || p[uuidlen] != '/')
+       type++;
+       typelen = strcspn(type, "/");
+       if (!typelen || type[typelen] != '/')
                return -EINVAL;
-       domid = xenbus_uuid_to_domid(p);
-       if (domid < 0)
-               return domid;
-       p += uuidlen + 1;
+
+       devid = strrchr(nodename, '/') + 1;
+
+       err = xenbus_gather(nodename, "frontend-id", "%i", &domid,
+                           "frontend", NULL, &frontend,
+                           NULL);
+       if (err)
+               return err;
+       if (strlen(frontend) == 0)
+               err = -ERANGE;
+
+       if (!err && !xenbus_exists(frontend, ""))
+               err = -ENOENT;
+
+       if (err) {
+               kfree(frontend);
+               return err;
+       }
 
        if (snprintf(bus_id, BUS_ID_SIZE,
-                    "%.*s-%i-%s", typelen, nodename, domid, p) >= BUS_ID_SIZE)
+                    "%.*s-%i-%s", typelen, type, domid, devid) >= BUS_ID_SIZE)
                return -ENOSPC;
        return 0;
 }
index 25b2d1ce800e1bfe4fc16bb96024569dc4c69e8b..685b5d7a3e68681eca2b4025e03a3ab3f68fdfda 100644 (file)
@@ -126,9 +126,6 @@ int register_xenbus_watch(struct xenbus_watch *watch);
 void unregister_xenbus_watch(struct xenbus_watch *watch);
 void reregister_xenbus_watches(void);
 
-/* For backends, does lookup on uuid (up to /).  Returns domid, or -errno. */
-int xenbus_uuid_to_domid(const char *uuid);
-
 /* Called from xen core code. */
 void xenbus_suspend(void);
 void xenbus_resume(void);